
Ext.namespace( 'Mappl' );

Mappl.ClassFactory = function(aClass, aTypeName) {
    this.aClass = aClass ;
    this.defaultType = aTypeName ;
    this.xtype = {};
    this.xtype[this.defaultType] = this.aClass ;
    return this ;
}
Mappl.ClassFactory.prototype = {
    getClass : function() { return this.aClass ; },
    getDefaultType : function() { return this.defaultType ; },
    create : function(aConfig) {
        var xtype = this.xtype[this.getDefaultType()];
        if ("xtype" in aConfig) xtype = aConfig.xtype ;
        if (typeof xtype == "string") xtype = this.xtype[xtype] ;
        if (typeof xtype != "function") throw new Mappl.Exception.IllegalArgumentsException(aConfig, "xtype");
        return new xtype(aConfig);
    },
    isInstance : function(aInstance) {
        return aInstance instanceof this.getClass();
    },
    get : function(aConfig) {
        if (this.isInstance(aConfig)) return aConfig ;
        if (typeof aConfig == 'object') return this.create(aConfig);
        throw new Mappl.Exception.IllegalArgumentsException(aConfig);
    }
}